<?php

namespace App\Admin\Extension\Expand;

use App\Models\TongUser;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Support\LazyRenderable;
use Dcat\Admin\Widgets\Card;
use Dcat\Admin\Widgets\Table;

class UsersChild extends LazyRenderable
{

    public function render()
    {
        // TODO: Implement render() method.
        $value = $this->key;
        $userChildRes = TongUser::query()->find($value);
        //获取用户
        $child_id = explode(',',$userChildRes['child_id']);
        $userChildVal = TongUser::whereIn('id',$child_id)->get();
        $titles = [
            '手机号',
            '昵称',
            '身份',
            '注册时间'
        ];
        $data = $userChildVal->map(function (TongUser $tongUser, $key) use ($userChildRes){
            return [
                'mobile'=>$tongUser->mobile,
                'name' => $tongUser->nickname,
                'identity_id'=>config('user.identity')[$tongUser->identity_id],
                'created_at' => $tongUser->created_at,
            ];
        })->toArray();
        //return Content::make()
        return Table::make($titles,$data);
    }
}
